<!DOCTYPE html>
<html dir="ltr">

<head>
  <meta charset="UTF-8">
  <title>Ionic Item Sliding</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
  <link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
  <script src="../../../../../scripts/testing/scripts.js"></script>
  <script nomodule src="../../../../../dist/ionic/ionic.js"></script>
  <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script></head>

<body>
  <ion-app>


    <ion-header>
      <ion-toolbar>
        <ion-title>Ionic CDN demo</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content>

      <ion-virtual-scroll id="virtual">
        <template>
          <ion-card>
            <ion-card-header>
              <ion-card-title>Card Header</ion-card-title>
            </ion-card-header>
            <ion-card-content class="content"></ion-card-content>
          </ion-card>
        </template>
      </ion-virtual-scroll>

    </ion-content>

  </ion-app>

  <script>
    const virtual = document.getElementById('virtual');
    virtual.approxItemHeight = 200;
    virtual.headerFn = (item, index) => {
      if (index % 20 === 0) {
        return 'Header ' + index;
      }
      return null;
    }

    function renderItem(el, item) {
      el.querySelector('.content').textContent = item.content;
      return el;
    }

    function renderHeader(el, item) {
      if (!el) {
        el = document.createElement('ion-item-divider');
      }
      el.textContent = item;
      return el;
    }

    virtual.nodeRender = (el, cell) => {
      if (cell.type === 'item') return renderItem(el, cell.value);
      return renderHeader(el, cell.value);
    };
    const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
    const items = [];
    for (var i = 0; i < 1000; i++) {
      items.push({
        content: lorem.substring(0, lorem.length * ((i % 4)+1) / 5)
      });
    }
    virtual.items = items;
  </script>

</body>

</html>
